//rastrigin problem-depended class
//$Id: rastrigin_ga.h 612 2010-11-28 18:40:53Z Oleg.Bulychov $
#pragma once

#include "../rastrigin.h"
#include "solvers/ga/ga_common.h"

template<>
struct solution<Rastrigin_Solution, ga_tag>:
    public Rastrigin_Solution
{
    typedef solution<Rastrigin_Solution, ga_tag> Rastrigin_Solution_GA;
public:
    mutable double wheel_sector_;

    template<class E>
    void cross(E* env, random_generator& rnd, Rastrigin_Solution_GA& genome)
    {//:simple one point crossover
        size_t j        = rnd.next_SizeT(env->problem_.n_);
        double beta     = rnd.next_Double();
        double delta    = beta*(data_[j]-genome.data_[j]);
        data_[j]        = data_[j]-delta;
        genome.data_[j] = genome.data_[j]+delta;
        for (size_t i = j + 1; i < size_t(env->problem_.n_); ++i)
        {
            std::swap(data_[i], genome.data_[i]);
        }
        changed_ = genome.changed_ = true;
    }

    template<class E>
    void mutate(E* env, random_generator& rnd, double mutationProbability)
    {
        for (size_t i = 0; i < env->problem_.n_; ++i)
        {
            if (rnd.next_Double() < mutationProbability)
            {
                data_[i] = env->problem_.lbound_+(env->problem_.rbound_-env->problem_.lbound_)*rnd.next_Double();
                changed_ = true;
            }
        }
    }

    TCostType get_Fitness() const { return get_Cost(); }
};
//__________________________________________________________________________________

//EOF!
